﻿// Tools_SetChart_Dlg.cpp: 实现文件
//

#include "pch.h"
#include "SakerProject.h"
#include "Tools_SetChart_Dlg.h"
#include "afxdialogex.h"

#include "xxFileProcess.h"
#include "mmFile_Paras.h"
#include "xxWidgetControl.h"

#include "mmCalib.h"


// CTools_SetChart_Dlg 对话框
CTools_SetChart_Dlg * m_Tools_SetChart;

IMPLEMENT_DYNAMIC(CTools_SetChart_Dlg, CDialogEx)

CTools_SetChart_Dlg::CTools_SetChart_Dlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_Tools_SetChart, pParent)
{

}

CTools_SetChart_Dlg::~CTools_SetChart_Dlg()
{
}

void CTools_SetChart_Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CTools_SetChart_Dlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_Save, &CTools_SetChart_Dlg::OnBnClickedButtonSave)
	ON_BN_CLICKED(IDC_BUTTON_Show, &CTools_SetChart_Dlg::OnBnClickedButtonShow)
	ON_BN_CLICKED(IDC_BUTTON_Close, &CTools_SetChart_Dlg::OnBnClickedButtonClose)
	ON_CBN_SELCHANGE(IDC_COMBO_ChartID, &CTools_SetChart_Dlg::OnCbnSelchangeComboChartid)
	ON_BN_CLICKED(IDC_BUTTON_DrawRect, &CTools_SetChart_Dlg::OnBnClickedButtonDrawrect)
	ON_BN_CLICKED(IDC_BUTTON_DrawChessBoard, &CTools_SetChart_Dlg::OnBnClickedButtonDrawchessboard)
END_MESSAGE_MAP()


// CTools_SetChart_Dlg 消息处理程序


BOOL CTools_SetChart_Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	xx::WriteCK(this, IDC_CHECK_AutoFullScreen, mmShowChart.Flag_AutoFullScreen);
	mmShowChart.SelScreen = xx::InitCB(this, IDC_COMBO_ScreenID, mmShowChart.vecScreenNames, mmShowChart.SelScreen);
	mmShowChart.SelChart = xx::InitCB(this, IDC_COMBO_ChartID, mmShowChart.vecChartNames, mmShowChart.SelChart);

	UpdateChartInfoWidget();

	return TRUE;
}

void CTools_SetChart_Dlg::UpdateChartInfoWidget() {
	xx::WriteCK(this, IDC_CHECK_FullScreen, mmShowChart.CurChart()->Flag_FullScreen);
	xx::WriteCK(this, IDC_CHECK_MaxFit, mmShowChart.CurChart()->Flag_MaxFit);
	xx::WriteWidget(this, IDC_EDIT_dx, mmShowChart.CurChart()->dx);
	xx::WriteWidget(this, IDC_EDIT_dy, mmShowChart.CurChart()->dy);
	xx::WriteWidget(this, IDC_EDIT_fx, mmShowChart.CurChart()->fx);
	xx::WriteWidget(this, IDC_EDIT_fy, mmShowChart.CurChart()->fy);

	xx::WriteCK(this, IDC_CHECK_DrawChessBoard, mmShowChart.CurChart()->Flag_DrawChessBoard);
	xx::WriteWidget(this, IDC_EDIT_RSquare, mmShowChart.CurChart()->ChessBoard_RSquare);
	xx::WriteWidget(this, IDC_EDIT_CSquare, mmShowChart.CurChart()->ChessBoard_CSquare);
	xx::WriteWidget(this, IDC_EDIT_ChessBoard_dx, mmShowChart.CurChart()->ChessBoard_dx);
	xx::WriteWidget(this, IDC_EDIT_ChessBoard_dy, mmShowChart.CurChart()->ChessBoard_dy);
}


void CTools_SetChart_Dlg::OnBnClickedButtonSave()
{
	CString iniCurrentPath = mmFile_Paras.iniModelPath();
	mmShowChart.Flag_AutoFullScreen = xx::DefaultCK(this, IDC_CHECK_AutoFullScreen, mmShowChart.iniField, L"AutoFullScreen", iniCurrentPath);
	mmShowChart.SelScreen = xx::DefaultCB(this, IDC_COMBO_ScreenID, mmShowChart.iniField, L"SelScreen", iniCurrentPath, 0);
	mmShowChart.SelChart = xx::DefaultCB(this, IDC_COMBO_ChartID, mmShowChart.iniField, L"SelChart", iniCurrentPath, 0);

	CString iniField = mmShowChart.CurChart()->BmpID;
	mmShowChart.CurChart()->Flag_FullScreen = xx::DefaultCK(this, IDC_CHECK_FullScreen, iniField, L"FullScreen", iniCurrentPath);
	mmShowChart.CurChart()->Flag_MaxFit = xx::DefaultCK(this, IDC_CHECK_MaxFit, iniField, L"MaxFit", iniCurrentPath);
	mmShowChart.CurChart()->dx = xx::DefaultWidget(this, IDC_EDIT_dx, iniField, L"dx", iniCurrentPath, 0);
	mmShowChart.CurChart()->dy = xx::DefaultWidget(this, IDC_EDIT_dy, iniField, L"dy", iniCurrentPath, 0);
	mmShowChart.CurChart()->fx = xx::DefaultWidget(this, IDC_EDIT_fx, iniField, L"fx", iniCurrentPath, 0.0);
	mmShowChart.CurChart()->fy = xx::DefaultWidget(this, IDC_EDIT_fy, iniField, L"fy", iniCurrentPath, 0.0);

	mmShowChart.CurChart()->Flag_DrawChessBoard = xx::DefaultCK(this, IDC_CHECK_DrawChessBoard, iniField, L"DrawChessBoard", iniCurrentPath);
	mmShowChart.CurChart()->ChessBoard_RSquare = xx::DefaultWidget(this, IDC_EDIT_RSquare, iniField, L"ChessBoard_RSquare", iniCurrentPath, 0);
	mmShowChart.CurChart()->ChessBoard_CSquare = xx::DefaultWidget(this, IDC_EDIT_CSquare, iniField, L"ChessBoard_CSquare", iniCurrentPath, 0);
	mmShowChart.CurChart()->ChessBoard_dx = xx::DefaultWidget(this, IDC_EDIT_ChessBoard_dx, iniField, L"ChessBoard_dx", iniCurrentPath, 0);
	mmShowChart.CurChart()->ChessBoard_dy = xx::DefaultWidget(this, IDC_EDIT_ChessBoard_dy, iniField, L"ChessBoard_dy", iniCurrentPath, 0);
}


void CTools_SetChart_Dlg::OnBnClickedButtonShow()
{
	mmShowChart.ShowCurrent();
}


void CTools_SetChart_Dlg::OnBnClickedButtonClose()
{
	mmShowChart.CurChart()->Close();
}


void CTools_SetChart_Dlg::OnCbnSelchangeComboChartid()
{
	mmShowChart.SelChart = ((CComboBox*)GetDlgItem(IDC_COMBO_ChartID))->GetCurSel();
	UpdateChartInfoWidget();
}


void CTools_SetChart_Dlg::OnBnClickedButtonDrawrect()
{
	int xL = xx::ReadWidget(this, IDC_STATIC_Rect_xL, 0);
	int xR = xx::ReadWidget(this, IDC_STATIC_Rect_xR, 0);
	int yT = xx::ReadWidget(this, IDC_STATIC_Rect_yT, 0);
	int yD = xx::ReadWidget(this, IDC_STATIC_Rect_yD, 0);
	mmShowChart.DrawRect(Point2i(xL, yT), Point2i(xR, yD), RGB(0, 0, 0));
}


void CTools_SetChart_Dlg::OnBnClickedButtonDrawchessboard()
{
	mmShowChart.DrawChessBoard(mmCalib.CornerPara.RCorners, mmCalib.CornerPara.CCorners, 40, 40, 0, 0);
}
